<template>
  <tr>
          <td>{{obj.id}}</td>
          <td>{{obj.name}}</td>
          <td>{{obj.date|datecope}}</td>
          <td>
            <button @click="deletefn(obj.id)" >删除</button>
            <button @click="modifyfn(obj.id)" >编辑</button>
          </td>
        </tr>
</template>

<script>
import moment from 'moment'
import axios from 'axios'
export default {
  props: {
    obj: {
      type: Object,
      required: true
    },
    list: {
      type: Array,
      required: true
    }
  },
  filters: {
    datecope (val) {
      return moment(val).format('YYYY-MM-DD')
    }
  },
  methods: {
    async deletefn (id) {
      console.log(id)
      if (!(this.list.length === 1)) {
        const res = await axios({
          url: 'books/' + id,
          method: 'DELETE'
        })
        console.log(res)
        console.log('删除成功')
        this.$emit('deleteupdate')
      }
    },
    async modifyfn (id) {
      const res = await axios({
        url: 'books/' + id
      })
      console.log(res)

      this.$emit('modify-name', res.data.name)
    }

  }
}
</script>

<style>

</style>
